/**
 * Created by Administrator on 2017/5/10.
 */
var roleType = sessionStorage.getItem("roleType");//从缓存拿角色的参数
if(roleType=='3'){
    $(".facilities-content").hide();
    $('#myModal').modal('show');
    setTimeout(function(){
        $("#myModal").modal("hide")
    },1200);
}else{
    $(".facilities-content").show();
}
var map = new BMap.Map("map");  // 创建Map实例
var point = new BMap.Point(119.014521, 25.459865);// 初始化地图,用城市名设置地图中心点
map.centerAndZoom(point, 14);//
map.enableScrollWheelZoom();//地图可以缩放
map.enableContinuousZoom();

var blist = [];
var districtLoading = 0;
function getBoundary() {
    addDistrict("莆田市");
}
/**
 * 添加行政区划
 * @param {} districtName 行政区划名
 * @returns  无返回值
 */
function addDistrict(districtName) {
    //使用计数器来控制加载过程
    districtLoading++;
    var bdary = new BMap.Boundary();
    bdary.get(districtName, function (rs) {       //获取行政区域
        var count = rs.boundaries.length; //行政区域的点有多少个
        if (count === 0) {
            alert('未能获取当前输入行政区域');
            return;
        }
        for (var i = 0; i < count; i++) {
            blist.push({ points: rs.boundaries[i], name: districtName });
        };
        //加载完成区域点后计数器-1
        districtLoading--;
        if (districtLoading == 0) {
            //全加载完成后画端点
            drawBoundary();
        }
    });
}

function drawBoundary() {
    //包含所有区域的点数组
    var pointArray = [];
    var pNW = { lat: 59.0, lng: 73.0 };
    var pNE = { lat: 59.0, lng: 136.0 };
    var pSE = { lat: 3.0, lng: 136.0 };
    var pSW = { lat: 3.0, lng: 73.0 };
    var pArray = [];
    pArray.push(pNW);
    pArray.push(pSW);
    pArray.push(pSE);
    pArray.push(pNE);
    pArray.push(pNW);
    //循环添加各闭合区域
    for (var i = 0; i < blist.length; i++) {
        //添加显示用标签层
        var label = new BMap.Label(blist[i].name, { offset: new BMap.Size(20, -10) });
        label.hide();
        map.addOverlay(label);

        //添加多边形层并显示
        var ply = new BMap.Polygon(blist[i].points, { strokeWeight: 1, strokeColor: "#FF0000", fillOpacity: 0.01, fillColor: " #FFFFFF" }); //建立多边形覆盖物
        ply.name = blist[i].name;
        ply.label = label;
        map.addOverlay(ply);


        //将点增加到视野范围内
        var path = ply.getPath();
        pointArray = pointArray.concat(path);
        //将闭合区域加到遮蔽层上，每次添加完后要再加一次西北角作为下次添加的起点和最后一次的终点
        pArray = pArray.concat(path);
        pArray.push(pArray[0]);
    }

    // //限定显示区域，需要引用api库
    // var boundply = new BMap.Polygon(pointArray);
    // BMapLib.AreaRestriction.setBounds(map, boundply.getBounds());
    // map.setViewport(pointArray);    //调整视野
    //添加遮蔽层
    var plyall = new BMap.Polygon(pArray, { strokeOpacity: 0.0000001, strokeColor: "#000000", strokeWeight: 0.00001, fillColor: "#000000", fillOpacity:0.6 }); //建立多边形覆盖物
    map.addOverlay(plyall);
}

getBoundary();


//声明八个对象用来缓存marker和Window，使用id来查询和添加缓存
var buildMap = null,
    buildWindowMap = null,
    coverMap = null,
   coverWindowMap = null,
    hanMap = null,
    hanWindowMap = null,
    valveMap=null,
    valveWindowMap = null,
    dtuMap = null,
    dtuWindowMap = null;
/**
 * 自定义map
 * @constructor
 */
function Map() {

    var mapObj = {};

    this.put = function (key, value) {
        mapObj[key] = value;
    };

    this.remove = function (key) {
        if (mapObj.hasOwnProperty(key)) {
            delete mapObj[key];
        }
    };

    this.get = function (key) {
        if (mapObj.hasOwnProperty(key)) {
            return mapObj[key];
        }
        return null;
    };

    this.getKeys = function () {
        var keys = [];
        for (var k in mapObj) {
            keys.push(k);
        }
        return keys;
    };

    // 遍历map
    this.each = function (fn) {
        for (var key in mapObj) {
            fn(key, mapObj[key]);
        }
    };

    this.toString = function () {
        var str = "{";
        for (var k in mapObj) {
            str += "\"" + k + "\" : \"" + mapObj[k] + "\",";
        }
        str = str.substring(0, str.length - 1);
        str += "}";
        return str;
    }

}
/***********************************************建筑方法***************************************************************/
/**查询全部地图上建筑**/
function queryBuild() {
    $.ajax({
        type: "GET",
        url: "/rest/web/index/selectArchitectureList",
        dataType: "json",
        data:{
            name: $("#name").val()
        },
        success: function (data) {
            //每次查询后都把marker和buildWindow缓存的数据清空掉
            buildMap = new Map();
            buildWindowMap = new Map();
            var buildList = data.data;
            $.each(buildList, function (i, o) {
                setBuildPoint(o);
            });
            var reportBuildHtml = "";
            $.each(buildList, function (i, n) {
                if (i == 0) {
                    getSingleBuild(n.id);
                    reportBuildHtml = reportBuildHtml + "<li data-id='" + n.id + "'> <p>" + n.sno + "</p><p>" + n.name + "</p></li>";
                }
                else {
                    reportBuildHtml = reportBuildHtml + "<li data-id='" + n.id + "'> <p>" + n.sno + "</p><p>" + n.name + "</p></li>";
                }
            });
            $("#reportBuild").html(reportBuildHtml);
            $("#reportBuild>li").click(function () {
                getSingleBuild($(this).attr("data-id"));
            });
            //求出总数的方法
            var dealWith = "";
            dealWith += "<p>总数：<span>" + buildList.length + "</span></p>"
            $("#buildTotal").html(dealWith);
        }
    });
}
function setBuildPoint(obj) {
    var buildContent = "";
    buildContent = buildContent + "<div class='facilities' id='buildDemo'>" +
        "<div  class='message'><h5>" + obj.name + "&nbsp; </h5><p> &nbsp; &nbsp; 状态：<span>使用中</span></p></div>" +
        "<div><h6>坐标：</h6><p class='coordinate'>" + obj.lng + "," + obj.lat + "</p></div>" +
        "<div><h6>地址：</h6><p>" + obj.address + "</p></div>" +
        "<div class='classify'>" +
        "<div><h6>类别：</h6><p>" + obj.type + "</p></div><div><h6>规格：</h6><p>" + obj.spec + "</p></div>" +
        "</div>" +
        "<div class='classify'>" +
        "<div><h6>编号：</h6><p>" + obj.sno + "</p></div><div><h6>寿命：</h6><p>" + obj.age + "</p></div>" +
        "</div>" +
        "<div class='classify'>" +
        "<div><h6>录入：</h6><p>" + obj.createTime + "</p></div><div><h6>责任：</h6><p>" + obj.personLiable + "</p></div>" +
        "</div>" +
        "<div class='classify'>" +
        "<div><h6>年份：</h6><p>" + obj.year + "</p></div><div><h6>部门：</h6><p>" + obj.department + "</p></div>" +
        "</div>" +
        "<div class='classify remarks'><h6>备注：</h6><p>" + obj.remarks + "</p></div>" +
        "</div>" +
        "</div>";
    var buildWindow = new BMap.InfoWindow(buildContent); // 创建信息窗口对象
    //创建建筑小图标
    var pt = new BMap.Point(obj.lng, obj.lat);
    var myIcon = new BMap.Icon("/static/images/map_building.png", new BMap.Size(22, 22));
    var marker = new BMap.Marker(pt, {icon: myIcon}); // 创建标注
    map.addOverlay(marker);
    marker.addEventListener("click", function () {
        this.openInfoWindow(buildWindow);
        //图片加载完毕重绘infowindow
        document.getElementById('buildDemo').onload = function () {
            buildWindow.redraw(); //防止在网速较慢，图片未加载时，生成的信息框高度比图片的总高度小，导致图片部分被隐藏
        }
    });
    //将marker和buildWindow缓存起来
    buildMap.put(obj.id, marker);
    buildWindowMap.put(obj.id, buildWindow);
}
/**
 * 根据id把缓存的marker和buildWindow拼装后调用map的openInfoWindow方法弹窗展示
 * @param id
 */
function getSingleBuild(id) {
    var infoWindow = buildWindowMap.get(id);
    var marker = buildMap.get(id);
    marker.openInfoWindow(infoWindow);
}
queryBuild();

/***********************************************涵匣方法***************************************************************/
/**创建涵匣的全部查询 **/
function queryHan() {
    $.ajax({
        type: "GET",
        url: "/rest/web/information/selectGatesList",
        dataType: "json",
        data:{
            name: $("#name").val()
        },
        success: function (data) {
            //每次查询后都把marker和hanWindow缓存的数据清空掉
            hanMap = new Map();
            hanWindowMap = new Map();
            var hanList = data.data;
            $.each(hanList, function (i, o) {
                setHanPoint(o);
            });
            var reportHanHtml = "";
            $.each(hanList, function (i, n) {
                if (i == 0) {
                    getSingleHan(n.id);
                    reportHanHtml = reportHanHtml + "<li data-id='" + n.id + "'> <p>" + n.sno + "</p><p>" + n.name + "</p></li>";
                }
                else {
                    reportHanHtml = reportHanHtml + "<li data-id='" + n.id + "'> <p>" + n.sno + "</p><p>" + n.name + "</p></li>";
                }
            });
            $("#reportHan").html(reportHanHtml);
            $("#reportHan>li").click(function () {
                getSingleHan($(this).attr("data-id"));
            });
            //求出总数的方法
            var dealWith = "";
            dealWith += "<p>总数：<span>" + hanList.length + "</span></p>";
            $("#boxTotal").html(dealWith);
        }
    });
}
/**
 * 绘制涵匣点
 * @param obj
 */
function setHanPoint(obj) {
    var hanContent = "";
    hanContent = hanContent + "<div class='facilities' id='senseDemo'>" +
        "<div class='message'><h5>" + obj.name + "&nbsp; </h5><p> &nbsp; &nbsp; 状态：<span>使用中</span></p></div>" +
        "<div><h6>坐标：</h6><p class='coordinate'>" + obj.lng + "," + obj.lat + "</p></div>" +
        "<div><h6>地址：</h6><p>" + obj.address+ "</p></div>" +
        "<div class='classify'>" +
        "<div><h6>类别：</h6><p>" + obj.type + "</p></div><div><h6>规格：</h6><p>" + obj.spec + "</p></div>" +
        "</div>" +
        "<div class='classify'>" +
        "<div><h6>编号：</h6><p>" + obj.sno + "</p></div><div><h6>寿命：</h6><p>" + obj.age + "</p></div>" +
        "</div>" +
        "<div class='classify'>" +
        "<div><h6>录入：</h6><p>" + obj.createTime+ "</p></div><div><h6>责任：</h6><p>" + obj.personLiable + "</p></div>" +
        "</div>" +
        "<div class='classify'>" +
        "<div><h6>年份：</h6><p>" + obj.year + "</p></div><div><h6>部门：</h6><p>" + obj.department + "</p></div>" +
        "</div>" +
        "<div class='classify remarks'><h6>备注：</h6><p>" + obj.remarks + "</p></div>" +
        "</div>" +
        "</div>";
    var hanWindow = new BMap.InfoWindow(hanContent); // 创建信息窗口对象
    //创建涵匣小图标
    var pt = new BMap.Point(obj.lng, obj.lat);
    var myIcon = new BMap.Icon("/static/images/map_hanza.png", new BMap.Size(22, 22));
    var marker = new BMap.Marker(pt, {icon: myIcon}); // 创建标注
    map.addOverlay(marker);
    marker.addEventListener("click", function () {
        this.openInfoWindow(hanWindow);
        //图片加载完毕重绘infowindow
        document.getElementById('hanDemo').onload = function () {
            hanWindow.redraw(); //防止在网速较慢，图片未加载时，生成的信息框高度比图片的总高度小，导致图片部分被隐藏
        }
    });
    //将marker和hanWindow缓存起来
    hanMap.put(obj.id, marker);
    hanWindowMap.put(obj.id, hanWindow);
}
/**
 * 根据id把缓存的marker和hanWindow拼装后调用map的openInfoWindow方法弹窗展示
 * @param id
 */
function getSingleHan(id) {
    var infoWindow = hanWindowMap.get(id);
    var marker = hanMap.get(id);
    marker.openInfoWindow(infoWindow);
}
queryHan();
/***********************************************井盖方法***************************************************************/
/**查询地图上全部井盖**/
function queryCover() {
    $.ajax({
        type: "GET",
        url: "/rest/web/index/selectManholeList",
        dataType: "json",
        data:{
                    name: $("#name").val()
                },
        success: function (data) {
            //每次查询后都把marker和coverWindow缓存的数据清空掉
            coverMap = new Map();
            coverWindowMap = new Map();
            var coverList = data.data;
            $.each(coverList, function (i, o) {
                setCoverPoint(o);
            });
            var reportCoverHtml = "";
            $.each(coverList, function (i, n) {
                if (i == 0) {
                    getSingleCover(n.id);
                    reportCoverHtml = reportCoverHtml + "<li data-id='" + n.id + "'> <p>" + n.sno + "</p><p>" + n.name + "</p></li>";
                }
                else {
                    reportCoverHtml = reportCoverHtml + "<li data-id='" + n.id + "'> <p>" + n.sno + "</p><p>" + n.name + "</p></li>";
                }
            });
            $("#reportCover").html(reportCoverHtml);
            $("#reportCover>li").click(function () {
                getSingleCover($(this).attr("data-id"));
            });
            //求出总数的方法
            var data = data.data;
            var dealWith = "";
            dealWith += "<p>总数：<span>" + data.length + "</span></p>";
            $("#coverTotal").html(dealWith);
        }
    });
}
/**
 * 绘制井盖的点
 * @param obj
 */
function setCoverPoint(obj) {
    var coverContent = "";
    coverContent = coverContent + "<div class='facilities' id='senseDemo'>" +
        "<div class='message'><h5>" + obj.name + "&nbsp; </h5><p> &nbsp; &nbsp; 状态：<span>使用中</span></p></div>" +
        "<div><h6>坐标：</h6><p class='coordinate'>" + obj.lng + "," + obj.lat + "</p></div>" +
        "<div><h6>地址：</h6><p>" + obj.address + "</p></div>" +
        "<div class='classify'>" +
        "<div><h6>类别：</h6><p>" + obj.type + "</p></div><div><h6>井深：</h6><p>" + obj.depth + "</p></div>" +
        "</div>" +
        "<div class='classify'>" +
        "<div><h6>编号：</h6><p>" + obj.sno + "</p></div><div><h6>规格：</h6><p>" + obj.spec + "</p></div>" +
        "</div>" +
        "<div class='classify'>" +
        "<div><h6>录入：</h6><p>" + obj.createTime + "</p></div><div><h6>材质：</h6><p>" + obj.quality + "</p></div>" +
        "</div>" +
        "<div class='classify'>" +
        "<div><h6>年份：</h6><p>" + obj.year + "</p></div><div><h6>寿命：</h6><p>" + obj.age + "</p></div>" +
        "</div>" +
        "<div class='classify'>" +
        "<div><h6>爬梯：</h6><p>" + obj.ladder + "</p></div><div><h6>责任：</h6><p>" + obj.personLiable + "</p></div>" +
        "</div>" +
        "<div class='classify'>" +
        "<div><h6>形状：</h6><p>" + obj.shape + "</p></div><div><h6>部门：</h6><p>" + obj.department + "</p></div>" +
        "</div>" +
        "<div class='classify'><h6>防护：</h6><p>" + obj.protect + "</p></div>" +
        "<div class='classify remarks'><h6>备注：</h6><p>" + obj.remarks + "</p></div>" +
        "</div>" +
        "</div>";
    var coverWindow = new BMap.InfoWindow(coverContent); // 创建信息窗口对象
    //创建井盖小图标
    var pt = new BMap.Point(obj.lng, obj.lat);
    var myIcon = new BMap.Icon("/static/images/map_covers.png", new BMap.Size(22, 22));
    var marker = new BMap.Marker(pt, {icon: myIcon}); // 创建标注
    map.addOverlay(marker);
    marker.addEventListener("click", function () {
        this.openInfoWindow(coverWindow);
        //图片加载完毕重绘infowindow
        document.getElementById('coverDemo').onload = function () {
            coverWindow.redraw(); //防止在网速较慢，图片未加载时，生成的信息框高度比图片的总高度小，导致图片部分被隐藏
        }
    });
    //将marker和coverWindow缓存起来
    coverMap.put(obj.id, marker);
    coverWindowMap.put(obj.id, coverWindow);
}
/**
 * 根据id把缓存的marker和coverWindow拼装后调用map的openInfoWindow方法弹窗展示
 * @param id
 */
function getSingleCover(id) {
    var infoWindow = coverWindowMap.get(id);
    var marker = coverMap.get(id);
    marker.openInfoWindow(infoWindow);
}
queryCover();
/***********************************************阀门方法***************************************************************/
/**查询地图上全部阀门**/
function queryValve() {
    $.ajax({
        type: "GET",
        url: "/rest/web/valve/selectValveList",
        dataType: "json",
        data:{
            name: $("#name").val()
        },
        success: function (data) {
            //每次查询后都把marker和coverWindow缓存的数据清空掉
            valveMap = new Map();
            valveWindowMap = new Map();
            var valveList = data.data;
            $.each(valveList, function (i, o) {
                setValvePoint(o);
            });
            var reportValveHtml = "";
            $.each(valveList, function (i, n) {
                if (i == 0) {
                    getSingleValve(n.id);
                    reportValveHtml = reportValveHtml + "<li data-id='" + n.id + "'> <p>" + n.sno + "</p><p>" + n.name + "</p></li>";
                }
                else {
                    reportValveHtml = reportValveHtml + "<li data-id='" + n.id + "'> <p>" + n.sno + "</p><p>" + n.name + "</p></li>";
                }
            });
            $("#reportValve").html(reportValveHtml);
            $("#reportValve>li").click(function () {
                getSingleValve($(this).attr("data-id"));
            });
            //求出总数的方法
            var dealWith = "";
            dealWith += "<p>总数：<span>" + valveList.length + "</span></p>";
            $("#valveTotal").html(dealWith);
        }
    });
}
/**
 * 绘制阀门的点
 * @param obj
 */
function setValvePoint(obj) {
    var valveContent = "";
    valveContent= valveContent+ "<div class='facilities' id='valveDemo'>" +
        "<div class='message'><h5>" + obj.name + "&nbsp; </h5><p> &nbsp; &nbsp; 状态：<span>使用中</span></p></div>" +
        "<div><h6>坐标：</h6><p class='coordinate'>" + obj.lng + "," + obj.lat + "</p></div>" +
        "<div><h6>地址：</h6><p>" + obj.address + "</p></div>" +
        "<div class='classify'>" +
        "<div><h6>类别：</h6><p>" + obj.type + "</p></div><div><h6>井深：</h6><p>" + obj.depth + "</p></div>" +
        "</div>" +
        "<div class='classify'>" +
        "<div><h6>编号：</h6><p>" + obj.sno + "</p></div><div><h6>规格：</h6><p>" + obj.spec + "</p></div>" +
        "</div>" +
        "<div class='classify'>" +
        "<div><h6>录入：</h6><p>" + new Date(obj.createTime ).Format('yyyy-MM-dd hh:mm:ss') + "</p></div><div><h6>材质：</h6><p>" + obj.quality + "</p></div>" +
        "</div>" +
        "<div class='classify'>" +
        "<div><h6>年份：</h6><p>" + obj.year + "</p></div><div><h6>寿命：</h6><p>" + obj.age + "</p></div>" +
        "</div>" +
        "<div class='classify'>" +
        "<div><h6>爬梯：</h6><p>" + obj.ladder + "</p></div><div><h6>责任：</h6><p>" + obj.personLiable + "</p></div>" +
        "</div>" +
        "<div class='classify'>" +
        "<div><h6>形状：</h6><p>" + obj.shape + "</p></div><div><h6>部门：</h6><p>" + obj.department + "</p></div>" +
        "</div>" +
        "<div class='classify'><h6>防护：</h6><p>" + obj.protect + "</p></div>" +
        "<div class='classify remarks'><h6>备注：</h6><p>" + obj.remarks + "</p></div>" +
        "</div>" +
        "</div>";
    var valveWindow = new BMap.InfoWindow(valveContent); // 创建信息窗口对象
    //创建阀门小图标
    var pt = new BMap.Point(obj.lng, obj.lat);
    var myIcon = new BMap.Icon("/static/images/map_valve.png", new BMap.Size(22, 22));
    var marker = new BMap.Marker(pt, {icon: myIcon}); // 创建标注
    map.addOverlay(marker);
    marker.addEventListener("click", function () {
        this.openInfoWindow(valveWindow);
        //图片加载完毕重绘infowindow
        document.getElementById('valveDemo').onload = function () {
            valveWindow.redraw(); //防止在网速较慢，图片未加载时，生成的信息框高度比图片的总高度小，导致图片部分被隐藏
        }
    });
    //将marker和coverWindow缓存起来
    valveMap.put(obj.id, marker);
    valveWindowMap.put(obj.id, valveWindow);
}
/**
 * 根据id把缓存的marker和coverWindow拼装后调用map的openInfoWindow方法弹窗展示
 * @param id
 */
function getSingleValve(id) {
    var infoWindow = valveWindowMap.get(id);
    var marker = valveMap.get(id);
    marker.openInfoWindow(infoWindow);
}
queryValve();
/***********************************************流量传感器方法***************************************************************/
/**查询地图上全部流量传感器**/
function queryDtu() {
    $.ajax({
        type: "GET",
        url: "/rest/web/device/selectDeviceList",
        dataType: "json",
        data:{
            name: $("#name").val()
        },
        success: function (data) {
            //每次查询后都把marker和coverWindow缓存的数据清空掉
            dtuMap = new Map();
            dtuWindowMap = new Map();
            var dtuList = data.data;
            $.each(dtuList, function (i, o) {
                setDtuPoint(o);
            });
            var reportDtuHtml = "";
            $.each(dtuList, function (i, n) {
                if (i == 0) {
                    getSingleDtu(n.deviceId);
                    reportDtuHtml= reportDtuHtml+ "<li data-id='" + n.deviceId+ "'> <p>" + n.code + "</p><p>" + n.name + "</p></li>";
                }
                else {
                    reportDtuHtml= reportDtuHtml+ "<li data-id='" + n.deviceId + "'> <p>" + n.code + "</p><p>" + n.name + "</p></li>";
                }
            });
            $("#reportDtu").html(reportDtuHtml);
            $("#reportDtu>li").click(function () {
                getSingleDtu($(this).attr("data-id"));
            });
            //求出总数的方法
            var dealWith = "";
            dealWith += "<p>总数：<span>" + dtuList.length + "</span></p>";
            $("#dtuTotal").html(dealWith);
        }
    });
}
/**
 * 绘制流量传感器的点
 * @param obj
 */
function setDtuPoint(obj) {
    var dtuContent = "";
    dtuContent= dtuContent+ "<div class='facilities' id='dtuDemo'>" +
        "<div class='message'><h5>" + obj.name + "&nbsp; </h5><p> &nbsp; &nbsp; 状态：<span>使用中</span></p></div>" +
        "<div><h6>坐标：</h6><p class='coordinate'>" + obj.lng + "," + obj.lat + "</p></div>" +
        "<div><h6>地址：</h6><p>" + obj.address + "</p></div>" +
        "<div class='classify'>" +
        "<div><h6>类别：</h6><p>流量传感器</p></div><div><h6>规格：</h6><p>" +(obj.spec== null ? " ": obj.spec) + "</p></div>" +
        "</div>" +
        "<div class='classify'>" +
        "<div><h6>编号：</h6><p>" + obj.code + "</p></div><div><h6>寿命：</h6><p>" + (obj.age== null ? " ":obj.age) + "</p></div>" +
        "</div>" +
        "<div class='classify'>" +
        "<div><h6>录入：</h6><p>" + new Date(obj.createTime ).Format('yyyy-MM-dd hh:mm:ss')+ "</p></div><div><h6>责任：</h6><p>" + (obj.personLiable== null ? " ":obj.personLiable) + "</p></div>" +
        "</div>" +
        "<div class='classify'>" +
        "<div><h6>年份：</h6><p>" + (obj.year== null ? " ":obj.year) + "</p></div><div><h6>部门：</h6><p>" + (obj.department== null ? " ":obj.department) + "</p></div>" +
        "</div>" +
        "<div class='classify remarks'><h6>备注：</h6><p>" + obj.remark + "</p></div>" +
        "</div>" +
        "</div>";
    var dtuWindow = new BMap.InfoWindow(dtuContent); // 创建信息窗口对象
    //创建流量传感器小图标
    var pt = new BMap.Point(obj.lng, obj.lat);
    //判断是否开启报警，是的情况下去判断报警阀值上限超过流量或者报警阀值下限小于等于0的情况下，小图标变成红色
    var myIcon;
    if(obj.isSysAlarmOn==1){
        if(obj.curFlow<obj.alarmThresholdLowerLimit || obj.curFlow>obj.alarmThresholdUpperLimit){
            myIcon = new BMap.Icon("/static/images/map_dtu1.png", new BMap.Size(22, 22));
        }else{
            myIcon = new BMap.Icon("/static/images/map_dtu.png", new BMap.Size(22, 22));
        }
    }else{
        myIcon = new BMap.Icon("/static/images/map_dtu.png", new BMap.Size(22, 22));
    }
    var marker = new BMap.Marker(pt, {icon: myIcon}); // 创建标注
    map.addOverlay(marker);
    marker.addEventListener("click", function () {
        this.openInfoWindow(dtuWindow);
        //图片加载完毕重绘infowindow
        document.getElementById('dtuDemo').onload = function () {
            dtuWindow.redraw(); //防止在网速较慢，图片未加载时，生成的信息框高度比图片的总高度小，导致图片部分被隐藏
        }
    });
    //将marker和coverWindow缓存起来
    dtuMap.put(obj.deviceId, marker);
    dtuWindowMap.put(obj.deviceId, dtuWindow);
}
/**
 * 根据id把缓存的marker和coverWindow拼装后调用map的openInfoWindow方法弹窗展示
 * @param id
 */
function getSingleDtu(deviceId) {
    var infoWindow = dtuWindowMap.get(deviceId);
    var marker = dtuMap.get(deviceId);
    marker.openInfoWindow(infoWindow);
}
queryDtu();
/*********************************************************************搜索框的模糊查询******************************************/
/**搜索框中传感的模糊查询**/
$("#blurBtn").click(function () {
    queryHan();
    queryBuild();
    queryCover();
    queryValve();
    queryDtu();
});

